package com.dog.basics.admin.controller.mtkj;


import cn.hutool.poi.excel.ExcelUtil;
import cn.hutool.poi.excel.ExcelWriter;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.dog.basics.bean.dto.admin.mtkj.StatisticsFromDto;
import com.dog.basics.bean.vo.admin.mtkj.*;
import com.dog.basics.common.util.POIUtil;
import com.dog.basics.common.util.PageParam;
import com.dog.basics.common.util.R;
import com.dog.basics.security.annotation.Inner;
import com.dog.basics.service.mtkj.IMtDeviceHospitalService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.AllArgsConstructor;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import java.util.List;

/**
 * <p>
 * 日报月报模块 前端控制器
 * </p>
 *
 * @author wph
 * @since 2020-09-29
 */
@RestController
@RequestMapping("/pc/device/statistics")
@Api(value = "日报月报模块", tags = "日报月报模块")
@AllArgsConstructor
public class MtDeviceStatisticsController {
    private final IMtDeviceHospitalService mtDeviceHospitalService;

    /**
     * @Description: 轮椅日报列表
     * @Param: OrderFromDto
     * @return: IPage<OrderVo>
     * @Author: wph
     * @Date:
     */

    @ApiOperation(value = "轮椅日报列表", notes = "pc:statistics:day")
    @GetMapping("/day")
    @PreAuthorize("@pms.hasPermission('pc:statistics:day')")
    public R<List<StatisticsDayVo>> day(StatisticsFromDto obj) {
        List<StatisticsDayVo> list = mtDeviceHospitalService.getDayList(obj);
        return R.ok(list);
    }

    /**
     * @Description: 轮椅日报列表导出
     * @Param: OrderFromDto
     * @return: IPage<OrderVo>
     * @Author: wph
     * @Date:
     */
    @ApiOperation(value = "轮椅日报列表导出", notes = "pc:statistics:exportDay")
    @GetMapping("/exportDay")
    //@PreAuthorize("@pms.hasPermission('pc:statistics:exportDay')")
    @Inner
    public void exportDay(StatisticsFromDto obj) {
        List<StatisticsExportDayChildrenVo> list = mtDeviceHospitalService.getExportDayList(obj);
        // 通过工具类创建writer，默认创建xls格式
        ExcelWriter writer = ExcelUtil.getBigWriter();
        writer.addHeaderAlias("time", "时间").setColumnWidth(0, 30);
        writer.addHeaderAlias("hospitalName", "医院名称").setColumnWidth(0, 50);
        writer.addHeaderAlias("orderNum", "订单数").setColumnWidth(0, 30);
        writer.addHeaderAlias("money", "实收").setColumnWidth(0, 30);
        writer.write(list, true);
        //out为OutputStream，需要写出到的目标流
        POIUtil.createExcel(writer, null);
    }

    /**
     * @Description: 轮椅月报列表
     * @Param: OrderFromDto
     * @return: IPage<OrderVo>
     * @Author: wph
     * @Date:
     */
    @ApiOperation(value = "轮椅月报列表", notes = "pc:statistics:month")
    @GetMapping("/month")
    @PreAuthorize("@pms.hasPermission('pc:statistics:month')")
    public R<List<StatisticsDayVo>> month(StatisticsFromDto obj) {
        List<StatisticsDayVo> list = mtDeviceHospitalService.getMonthList( obj);
        return R.ok(list);
    }

    /**
     * @Description: 轮椅月报列表导出
     * @Param: OrderFromDto
     * @return: IPage<OrderVo>
     * @Author: wph
     * @Date:
     */
    @ApiOperation(value = "轮椅月报列表导出", notes = "pc:statistics:exportMonth")
    @GetMapping("/exportMonth")
    @PreAuthorize("@pms.hasPermission('pc:statistics:exportMonth')")
    public void exportMonth(StatisticsFromDto obj) {
        List<StatisticsExportDayChildrenVo> list = mtDeviceHospitalService.getExportMonthList(obj);
        // 通过工具类创建writer，默认创建xls格式
        ExcelWriter writer = ExcelUtil.getBigWriter();
        writer.addHeaderAlias("time", "时间").setColumnWidth(0, 30);
        writer.addHeaderAlias("hospitalName", "医院名称").setColumnWidth(0, 50);
        writer.addHeaderAlias("orderNum", "订单数").setColumnWidth(0, 30);
        writer.addHeaderAlias("money", "实收").setColumnWidth(0, 30);
        writer.write(list, true);
        //out为OutputStream，需要写出到的目标流
        POIUtil.createExcel(writer, null);
    }
}
